<template>
	<view class="u-grid" :class="{'u-border-top u-border-left': border}" :style="[gridStyle]"><slot /></view>
</template>

<script>

export default {
	name: 'u-grid',
	props: {
		
		col: {
			type: [Number, String],
			default: 3
		},
		
		border: {
			type: Boolean,
			default: true
		},
		
		align: {
			type: String,
			default: 'left'
		},
		
		hoverClass: {
			type: String,
			default: 'u-hover-class'
		}
	},
	data() {
		return {
			index: 0,
		}
	},
	watch: {
		
		parentData() {
			if(this.children.length) {
				this.children.map(child => {
					
					typeof(child.updateParentData) == 'function' && child.updateParentData();
				})
			}
		},
	},
	created() {
		
		this.children = [];
	},
	computed: {
		
		parentData() {
			return [this.hoverClass, this.col, this.size, this.border];
		},
		
		gridStyle() {
			let style = {};
			switch(this.align) {
				case 'left':
					style.justifyContent = 'flex-start';
					break;
				case 'center':
					style.justifyContent = 'center';
					break;
				case 'right':
					style.justifyContent = 'flex-end';
					break;
				default: style.justifyContent = 'flex-start';
			};
			return style;
		}
	},
	methods: {
		click(index) {
			this.$emit('click', index);
		}
	}
};
</script>

<style scoped lang="scss">
@import "../../libs/css/style.components.scss";

.u-grid {
	width: 100%;
	/* #ifdef MP */
	position: relative;
	box-sizing: border-box;
	overflow: hidden;
	/* #endif */
	
	/* #ifndef MP */
	@include vue-flex;
	flex-wrap: wrap;
	align-items: center;
	/* #endif */
}
</style>
